package main

import (
	"context"
	"fmt"
	"go_keep_learning/grpc/03grpc/pb"
	"net"

	"google.golang.org/grpc"
)

type server struct {
	pb.UnimplementedGreeterServer
}

func (s *server) SayHello(ctx context.Context, req *pb.HelloReq) (rep *pb.HelloResp, e error) {

	return &pb.HelloResp{Message: "hello" + req.GetName()}, nil
}
func (s *server) SayHelloAgain(ctx context.Context, req *pb.HelloReq) (rep *pb.HelloResp, e error) {

	return &pb.HelloResp{Message: "helloAgin" + req.GetName()}, nil
}

func main() {

	// 初始化 grpc 对象
	grpcServer := grpc.NewServer()

	//注册服务
	pb.RegisterGreeterServer(grpcServer, new(server))

	//监听
	listen, err := net.Listen("tcp", ":8800")
	if err != nil {
		fmt.Println("listen err", err)
		return
	}
	defer listen.Close()

	//run
	grpcServer.Serve(listen)
}
